class OpenWeatherApi {
  final String apiKey;

  OpenWeatherApi(this.apiKey);

  static const String _baseUrl = 'api.openweathermap.org';
  static const String _path = 'data/2.5/';

  Uri weather(String city) => _buildUri(
      endpoint: "weather", parametersBuilder: () => cityQueryParameters(city));

  Uri forecast(String city) => _buildUri(
      endpoint: "forecast", parametersBuilder: () => cityQueryParameters(city));

  Uri _buildUri(
      {required String endpoint,
      required Map<String, dynamic> Function() parametersBuilder}) {
    return Uri(
        scheme: "https",
        host: _baseUrl,
        path: _path + endpoint,
        queryParameters: parametersBuilder());
  }

  Map<String, dynamic> cityQueryParameters(String city) =>
      {"q": city, "appid": apiKey, "units": "metric"};
}
